import httpRequest from '@/http/request'
import { reactive, ref } from 'vue'
interface aquariumMessageParm {
    charge: string;
    fishNum: number;
    phone: string;
    gmtCreate: string;
    id: number;
    value1: string;
    value2: string;
    value3: string;
    value4: string;
    value5: string;
}
interface addAquariumParm {
    aquarium: string,
    username: string
}
interface addAdminAquariumParm {
    username: string,
    ip: string,
    port: string
}
const username = sessionStorage.getItem('username')
const id = sessionStorage.getItem('aquarium')

export async function ApiGetMessages(id: number) {
    const { data: res } = await httpRequest.get(`/web/aquarium/aquariumMess/${id}`)
    let aquariumMess: aquariumMessageParm = Object.assign({ id: id }, res.data.aquariumMess as aquariumMessageParm)
    return aquariumMess
}

export function ApiGetIdList() {
    return httpRequest.get(`/web/aquarium/aquariumIdList/${username}`)
}

export async function ApiAddAquarium(addAquariumModel: addAquariumParm) {
    const { data: res } = await httpRequest.get(`/web/user/add_or_restart/${addAquariumModel.aquarium}/${addAquariumModel.username}`)
    return res.success
}

export async function ApiAddAdminAquarium(addAdminAquariumModel: addAdminAquariumParm) {
    let { data: res } = await httpRequest({
        url: `/web/aquarium/addEquipment/${addAdminAquariumModel.username}`,
        method: 'post',
        data: {
            ip: addAdminAquariumModel.ip,
            port: addAdminAquariumModel.port
        }
    })
    return res.success
}

export async function ApiAddFishPic(formData: any) {
    let config = {
        headers: {
            "Content-Type": "multipart/form-data",
        },
    };
    return httpRequest.post("/web/aquarium/addFishPic", formData, config)
}

// /web/aquarium/addFish/
export async function ApiAddFish(addFishModel: any) {
    return httpRequest.post( `/web/aquarium/addFish/${id}`,addFishModel)
}

export async function ApiGetAllFish(){
    return httpRequest.get(`/web/aquarium/getAllFish/${id}`)
}